begintownscript;

variables;
short creature_count = 0;
short choice = 0;
short pc_counter = 0;
short lead_char = 0;
string paranoia;

body;

beginstate 0; //INIT_STATE
	set_crime_tolerance(2);
	relocate_character(0,25,17);
	relocate_character(1,25,18);
	relocate_character(2,25,19);
	relocate_character(3,25,20);
	set_character_facing(1000,2);
	change_outdoor_location(0,0,26,31);

	//start the cutscene proper
	set_state_continue(10);
break;


beginstate 1; //EXIT_STATE

	//Huge hint-giving dialog
	reset_dialog();
	add_dialog_str(0,"As you stumble away from the horrid sight of the ruined Hektos, you begin to wonder what could've possibly caused it. Obviously some sort of explosives, but then that begs the question of who set them off?",0);

	//rebels, heard both Anderson and Karl
	if((get_flag(0,3) == 1) && (get_flag(0,12) == 1)) {
		add_dialog_str(1, "After what Karl and Mayor Anderson said about rebels in the valley, it seems likely that they'd be involved, particularly with Fort Galima's presence here.",0);
		add_dialog_str(2, "Of course, they could've just gone for the fort itself and saved themselves some time.",0);
		set_flag(7,0,1);
		}
	//rebels, heard only Karl
	else if((get_flag(0,3) == 1) && (get_flag(0,12) == 0)) {
		add_dialog_str(1, "After what Karl said about rebels in the valley, you can't help but think that they might be involved, particularly with Fort Galima's presence here.",0);
		add_dialog_str(2, "Of course, trusting rumors overheard by an innkeeper might not be the best idea.",0);
		set_flag(7,0,1);
		}
	//rebels, heard only Anderson
	else if((get_flag(0,3) == 0) && (get_flag(0,12) == 1)) {
		add_dialog_str(1, "After what Mayor Anderson said about rebels in the valley, you can't help but think that they might be involved, particularly with Fort Galima's presence here.",0);
		add_dialog_str(2, "Of course, Anderson could be mistaken about the rebels' presence.",0);
		set_flag(7,0,1);
		}
	
	//appending "Also, " ... way too much work for one word.
	if(get_flag(7,0) == 1) {
		clear_buffer();
		append_string("Also, ");
		}

	//Empire, heard both Anderson and official
	if((get_flag(0,20) == 3) && (get_flag(0,21) == 1)) {

		if(get_flag(7,0) != 1)
			add_dialog_str(3, "After seeing Mayor Anderson fly off the handle at that Empire official, and hearing the mayor's rant against the Empire, it sounds plausible that the Empire would want to get rid of him.",0);
		else {
			append_string("since you saw Mayor Anderson fly off the handle at that Empire official, and heard the mayor's rant against the Empire, it seems plausible that the Empire would want to get rid of him.");
			get_buffer_text(paranoia);
			add_dialog_str(3,paranoia,0);
			}
		add_dialog_str(4, "Then again, the Empire would never go to such extreme lengths to kill one man, right?",0);
		}
	//Empire, heard only official
	else if((get_flag(0,20) == 3) && (get_flag(0,21) == 0)) {
		if(get_flag(7,0) != 1)
			add_dialog_str(3, "After the incident between Mayor Anderson and that Empire official, you can't help but wonder if maybe the Empire wanted to get rid of the mayor.",0);
		else {
			append_string("having seen that incident between Mayor Anderson and that Empire official, you wonder if maybe the Empire wanted to get rid of the mayor.");
			get_buffer_text(paranoia);
			add_dialog_str(3,paranoia,0);
			}
		add_dialog_str(4, "Then again, the Empire would never sink to such depths, right?",0);
		}
	//Empire, heard only Anderson
	else if((get_flag(0,20) != 3) && (get_flag(0,21) == 1)) {
		if(get_flag(7,0) != 1)
			add_dialog_str(3, "After hearing Mayor Anderson's rant against the Empire, you can't help but wonder if maybe they were out to get him after all.",0);
		else {
			append_string("since you heard Mayor Anderson's rant against the Empire, you can't help but wonder if maybe they were out to get him after all.");
			get_buffer_text(paranoia);
			add_dialog_str(3,paranoia,0);
			}
		add_dialog_str(4, "Then again, Anderson could've just been a paranoid old man.",0);
		}

	if((get_flag(0,20) != 3) && (get_flag(0,21) == 0) && (get_flag(0,3) == 0) && (get_flag(0,12) == 0)) {
		add_dialog_str(3, "Try as you might, you can't think of anything plausible. Your best guess is goblins.",0);
		}

	run_dialog(1);

break;


beginstate 2; //START_STATE
	pc_counter = 0;
	while(char_ok(pc_counter) == 0) {
		pc_counter = pc_counter + 1;
		}
	lead_char = pc_counter;

break;


beginstate 10; //TEH CUTSCENE!!!

	force_view_center(25,17);
	force_instant_terrain_redraw();

	pause(5);
	reset_dialog();
	add_dialog_str(0,"You reach the edge of the cliff overlooking the valley's lake, and see nothing that could've caused the noise. All you can see is the crystal clear water about a hundred feet below you.",0);
	add_dialog_str(1,"Then, the rumbling sounds return, slowly growing louder. As they increase in volume, you begin to think that the noises are coming from across the lake.",0);
	add_dialog_str(2,"You scan the landscape for any signs of activity.",0);
	run_dialog(1);
	pause(5);

	force_view_center(8,11);
	set_total_visibility(1);
	force_instant_terrain_redraw();
	pause(10);

	//First echoing rumble
	play_sound(-108);
	pause(3);
	play_sound(-108);
	pause(3);
	play_sound(-108);
	pause(15);

	//Second echoing rumble
	play_sound(-108);
	pause(3);
	play_sound(-108);
	pause(2);
	play_sound(-108);
	pause(3);
	play_sound(-108);
	pause(15);

	//Third echoing rumble
	play_sound(-108);
	pause(3);
	play_sound(-108);
	pause(2);
	play_sound(-108);
	pause(2);
	play_sound(-108);
	pause(3);
	play_sound(-108);
	pause(18);

	//Final echoing rumble, explosion
	play_sound(-108);
	pause(3);
	play_sound(-108);
	pause(2);
	play_sound(-108);
	pause(1);
	play_sound(-108);
	pause(2);
	play_sound(-108);
	pause(3);
	play_sound(-108);
	pause(2);
	play_sound(-108);
	pause(1);
	play_sound(-108);
	pause(2);

	//roast mayor's office
	set_floor(7,10,89);
	set_terrain(7,10,483);
	force_instant_terrain_redraw();
	put_boom_on_space(7,10,1,0);
	run_animation_sound(152);

	//burn the town
	set_terrain(7,9,479);
	set_terrain(7,11,480);
	set_terrain(8,10,479);
	set_terrain(8,11,481);
	set_terrain(6,11,481);
	set_terrain(8,9,482);
	set_terrain(6,9,484);
	set_terrain(6,10,138);
	force_instant_terrain_redraw();
	put_effect_on_space(7,10,1,9,1);
	put_effect_on_space(7,11,1,7,1);
	put_effect_on_space(7,9,1,7,1);
	put_effect_on_space(6,10,1,7,1);
	put_effect_on_space(8,10,1,7,1);
	put_effect_on_space(8,11,1,7,1);
	put_effect_on_space(8,9,1,7,1);
	put_effect_on_space(6,11,1,7,1);
	put_effect_on_space(6,9,1,7,1);
	run_animation_sound(51);

	pause(5);
	message_dialog("In a blinding flash of light, the town of Hektos simply disappears from the lake's edge, and is quickly replaced by a scorched ruin. The sound is absolutely deafening.","A few fires spring up, and promptly begin to prey on what's left of the buildings.");

	set_flag(0,25,4);  //THE FLAG
	set_flag(10,1,2);  //Miali goes missing

	pause(15);

	set_total_visibility(0);
	force_view_center(char_loc_x(lead_char),char_loc_y(lead_char));
	force_instant_terrain_redraw();

	pause(2);
	reset_dialog();
	add_dialog_str(0, "You rub your eyes in disbelief as the last shockwaves rebound across the valley. That can't have been real. You felt a blast of hot air and saw a flash of flames, but you just can't believe it.",0);
	add_dialog_str(1, "Staring at the hillside, you are forced to come to grips with the fact that there used to be a town there. And now there isn't.",0);
	add_dialog_str(2," ",0);
	add_dialog_str(3, "At a loss for what to do, you weigh your options.",0);
	add_dialog_str(4,"You could report to Fort Galima. You could just leave the valley before someone tries to blame you. And of course, you could head straight for the ruins to see if anyone survived.",0);
	run_dialog(1);

break;